package com.oo.viewlib.fragments


import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import com.oo.chartlibrary.charts.PieChartView

import com.oo.viewlib.R


/**
 * A simple [Fragment] subclass.
 */
class PieChartFragment : Fragment() {

    var pieChart: PieChartView? = null
    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        val root = inflater!!.inflate(R.layout.fragment_pie_chart, container, false)

        pieChart = root
                .findViewById<PieChartView>(R.id.pie_chart)

        root.findViewById<Button>(R.id.button).setOnClickListener {
            setData()
        }
        return root
    }

    override fun onAttach(context: Context?) {
        super.onAttach(context)

    }

    fun setData(){
        pieChart?.setItemDatas(fakeData())
    }


    private fun fakeData(): ArrayList<PieChartView.ItemData> {
        val datas = ArrayList<PieChartView.ItemData>()
        var data = PieChartView.ItemData()


        data.setColor(Color.RED)
        data.setValue(1);
        data.setDataName("红")
        datas.add(data)
        data = PieChartView.ItemData()

        data.setColor(Color.YELLOW)
        data.setValue(2);
        data.setDataName("黄")
        datas.add(data)

        data = PieChartView.ItemData()
        data.setColor(Color.BLUE)
        data.setValue(3);
        data.setDataName("蓝")
        datas.add(data)

        data = PieChartView.ItemData()
        data.setColor(Color.GREEN)
        data.setValue(3);
        data.setDataName("绿")
        datas.add(data)
        return datas
    }

}// Required empty public constructor
